package com.bling.action;

import java.sql.SQLException;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.bling.action.base.BaseAction;
import com.bling.common.bean.Kind;
import com.bling.common.constant.ActionReturn;
import com.bling.common.page.PageResult;
import com.bling.common.util.CommonTypeChange;
import com.bling.iservice.IKindService;
/**
 * 分类分页操作业务逻辑处理
 * @author chen-zhenxing
 *
 */
@Controller
@Scope("prototype")
public class KindPageAction extends BaseAction {

	private static final long serialVersionUID = -1046306046581183869L;

	/**
	 * 分页显示分类
	 * @return
	 */
	public String page(){
		int ps = CommonTypeChange.getIntFromString(this.getS());
		if(ps<1)
			ps=PageResult.getDefaultPageSize();
		int pc = CommonTypeChange.getIntFromString(this.getC());
		if(pc<1)
			pc=1;
		try {
			this.setPageData(kindService.listKindByPage((pc-1)*ps,ps));
			pageData.setPagesize(ps);
			pageData.setPagecurrent(pc);
		} catch (SQLException e) {
			return ActionReturn.ERROR;
		}
		return ActionReturn.JSP;
	}
	
	/**
	 * 单页数据
	 */
	private PageResult<Kind> pageData;
	/**
	 * 以下缩写为了在页面url中地址显示简单
	 * 防止被轻易看出地址
	 */
	private String s; // 每页显示条数缩写
	private String c; // 当前第几页缩写

	/**
	 * 分类服务
	 */
	@Resource
	private IKindService kindService;

	public PageResult<Kind> getPageData() {
		return pageData;
	}

	public void setPageData(PageResult<Kind> pageData) {
		this.pageData = pageData;
	}

	public String getS() {
		return s;
	}

	public void setS(String s) {
		this.s = s;
	}

	public String getC() {
		return c;
	}

	public void setC(String c) {
		this.c = c;
	}

	public IKindService getKindService() {
		return kindService;
	}

	public void setKindService(IKindService kindService) {
		this.kindService = kindService;
	}
}
